<!--------------------------------------------------------------
>//	Company:	HTHK
>//	NAME:	    GDAReport.jsp
//				Group Detail 
>//	TITLE:	    Monthly Jobs Report by Group
>//	FUNCTION:	Report Monthly Jobs by Group
>//	BY:	        Mike Cheng
>//	DATE:	    29/1/2004
>// --------------------------------------------------------------
>// MODIFICATION HISTORY
>// --------------------------------------------------------------
>//	CR Log #:  99999  BY:  XXXX   DATE:  dd/mm/yyyy
>//	ERROR:	XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
>//	FIX:	XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
>// --------------------------------------------------------------
-->

<html>
<%@ include file="../tssheader.jsp" %>
<%@ page import="java.util.*" %>
<%@ page import="java.lang.*" %>
<%@ page import="tss.options.*" %>
<%@ page import="tss.projectreport.*" %>
<body>
<%    
Vector vec = (Vector)request.getAttribute("vec");
Vector year_month = (Vector)request.getAttribute("year_month");

String company_code = "";
company_code = request.getParameter("company_code");

String group = "";
if(request.getParameter("cOrg_name") != null && request.getParameter("cOrg_name").length() != 0)
	group = request.getParameter("cOrg_name");

ChangeNum num = new ChangeNum();
boolean lSumCostBoolean = true;
%>

<body >
<h2>Monthly Report By Project Group</h2>
<table>
<tr>
	<td>Cost Center: </td>
	<td><%=company_code%></td>
</tr>
<%	
	if(group.length() != 0)
	{
%>
<tr>
	<td>Project Group: </td>
	<td><%=group%></td>
</tr>
<%
	}
%>
</table>

<%
//To display report for every month.
for(int i=0;i<vec.size();i++)
{ 
	ChargeReportContainer l_rptCont = (ChargeReportContainer)vec.get(i);
	
	ArrayList lAl_groupNameList =  l_rptCont.getCategoryNameList();
	HashMap lHs_gradeTotal =  l_rptCont.getGradeTotal();
	HashMap lHs_groupTotal =  l_rptCont.getCategoryTotal();
	HashMap lHs_gradeGroupTotal =  l_rptCont.getGradeCategoryTotal();
	float lv_total = l_rptCont.getTotal();
	Float  lF_total = new Float(lv_total);
	ArrayList lAl_gradeNameList =  l_rptCont.getGradeNameList();
	
	HashMap lHm_Rate =  l_rptCont.getRate();

	HashMap lHs_costList = new HashMap();
	
	String[] str_year_month = new String[1];
	str_year_month = (String[])year_month.get(i);
	int colnum = lAl_groupNameList.size();                             	
 %>
<br> 
<table>
	<tr>
		<td>Date From: </td>
		<td><%=str_year_month[0]+"/"+str_year_month[1]%></td>
	</tr>
	<tr>
		<td>Date To: </td>
		<td><%=str_year_month[0]+"/"+str_year_month[2]%></td>
	</tr>
</table>

<table border=1>
	<tr>
		<td align='center' rowspan=2><b>Grade</b></td>
		<td align='center' rowspan=2><b>Chargeable</b></td>			
		<td align='center' colspan='<%=colnum+1%>' ><b>Number of hour by Project Group(Hours)</b></td>
		<td align='center' rowspan=2><b>Avg. by Grade</b></td>
		<td align='center' rowspan=2><b>Cost RMB</b></td>
		<td align='center' rowspan=2><b>Charge-out rate RMB</b></td>
		<td align='center' rowspan=2><b>Service Fees RMB</b></td>
		<td align='center' rowspan=2><b>Profit RMB</b></td>
	</tr>
	<tr>
		<% for(int j=0;j<colnum;j++){ %>
		<td width=60 align='center'><b><%=(String)lAl_groupNameList.get(j)%></b></td>
		<% } %>
		<td width=60 align='center'><b>Total</b></td>
	</tr>
<%
	//To display every grade.
	for (int k=0;k<lAl_gradeNameList.size();k++)
	{
		String ls_GradeName = (String)lAl_gradeNameList.get(k);
%>
	<tr>
		<td rowspan=2 nowrap><b><%=ls_GradeName%></b></td>
		<td nowrap><b>Y</b></td>		
<%
	//To display records of every category of this grade.
	String  ls_GroupName = "";
	for (int m=0;m<lAl_groupNameList.size();m++)
	{
		ls_GroupName = (String)lAl_groupNameList.get(m);
		Float lF_hours = (Float)lHs_gradeGroupTotal.get(ls_GradeName+"~Y~"+ls_GroupName);
		String ls_hours = "";
		if (lF_hours!=null)
		{
			ls_hours = lF_hours.toString();
		}
		Float lF_Rate = (Float)lHm_Rate.get(ls_GradeName);
		float cost = 0f;
		if(lF_hours != null)
		{
			if(lF_Rate != null)
			{
				cost = Math.round(lF_Rate.floatValue()*lF_hours.floatValue());
				Float l_cost = new Float(0f);
				if(ls_GroupName != null)
				{
					l_cost = (Float)lHs_costList.get(ls_GroupName);
					if (l_cost != null)
					{
						if(  l_cost.floatValue()>=0f)
						{
							cost = l_cost.floatValue() + cost;
							Float gh = new Float(cost);
							lHs_costList.put(ls_GroupName,gh);
						}
					}
					else
					{
						Float gh = new Float(cost);
						lHs_costList.put(ls_GroupName,gh);
					}
				}
			}
			else
			{
				Float gh = new Float(-9999);
				lHs_costList.put(ls_GroupName,gh);
			}
		}
		else
		{
			Float l_cost = (Float)lHs_costList.get(ls_GroupName);
			if (l_cost == null)
			{
				Float gh = new Float(0);
				lHs_costList.put(ls_GroupName,gh);			
			}			
		}		
%>
		<td nowrap width=60 align='right'>
		<%=((num.getFixNum(ls_hours,2)).length()==0?"&nbsp;":num.getFixNum(ls_hours,2))%>
		</td>
<%
	}
	//To display total of normal records of this grade of this category.
	Float gradehours = (Float)lHs_gradeTotal.get(ls_GradeName+"~Y");
	float gradepercent = 0;
	if (gradehours != null)
	{
		gradepercent = Math.round(gradehours.floatValue()*10000f/lF_total.floatValue())/100f;
	}
	else
	{
		gradehours = new Float("0");
	}
%>
		<td nowrap width=60 align='right'><%=num.getFixNum(gradehours.toString(),2)%></td>
		<td align='right'><%=num.getFixNum(String.valueOf(gradepercent),2)%>%</td>
<%
	//Calculate cost of overtime records of this grade of this category.
	Float lF_Rate = (Float)lHm_Rate.get(ls_GradeName);
	if (lF_Rate != null)
	{
		float lf_Cost = Math.round(lF_Rate.floatValue()*gradehours.floatValue());
%>
		<td nowrap width=60 align='right'><%=num.getFixNum(new Float(lf_Cost).toString(),-1)%></td>
		<td nowrap width=60 align='right'><%=num.getFixNum(lF_Rate.toString(),-1)%></td>
<%
	}
	else
	{
		if(gradehours.floatValue() == 0)
		{
%>                                 
		<td nowrap width=60 align='right'>0.00</td>
<%  
		}
		else
		{
%>
		<td nowrap width=60 align='right'>*</td>
<%      
		}
%>
		<td nowrap width=60 align='right'>*</td>
<%
	}
 %>
	<td>&nbsp;</td>
	<td>&nbsp;</td>       
</tr>
<tr>
	<td nowrap><b>N</b></td>
<%
	for (int m=0;m<lAl_groupNameList.size();m++)
	{
		ls_GroupName = (String)lAl_groupNameList.get(m);
		Float lF_hours = (Float)lHs_gradeGroupTotal.get(ls_GradeName+"~N~"+ls_GroupName);
		String ls_hours = "";
		if (lF_hours!=null)
		{
			ls_hours = lF_hours.toString();
		}
%>
		<td nowrap width=60 align='right'>
		<%=((num.getFixNum(ls_hours,2)).length()==0?"&nbsp;":num.getFixNum(ls_hours,2))%>
		</td>
<%
	}
	gradehours = (Float)lHs_gradeTotal.get(ls_GradeName+"~N");
	gradepercent = 0;
	if (gradehours != null)
	{
		gradepercent = Math.round(gradehours.floatValue()*10000f/lF_total.floatValue())/100f;
	}
	else
	{
		gradehours = new Float("0");
	}
%>
		<td nowrap width=60 align='right'><%=num.getFixNum(gradehours.toString(),2)%></td>
		<td align='right'><%=num.getFixNum(String.valueOf(gradepercent),2)%>%</td>
		<td nowrap width=60 align='right'>&nbsp;</td>
		<td nowrap width=60 align='right'>&nbsp;</td>
	<td>&nbsp;</td>
	<td>&nbsp;</td>       
</tr>
<%
	}
%>
<tr>
	<td nowrap><b>Sub-total</b></td>
	<td>&nbsp;</td>
<% 
	for (int n=0;n<lAl_groupNameList.size();n++)
	{
		String ls_group = "";
		ls_group = (String)lAl_groupNameList.get(n);
		Float grouphours = new Float(0f);
		grouphours = (Float)lHs_groupTotal.get(ls_group);
%>
	<td width=60 align='right'>
		<%=num.getFixNum(grouphours.toString(),2)%>
	</td>
<% 
	} 
%>
	<td width=60 align='right'><%=num.getFixNum(lF_total.toString(),2)%></td>
	<td width=60 align="right">100.00%</td>
	<td>&nbsp;</td>
	<td>&nbsp;</td>
	<td>&nbsp;</td>
	<td>&nbsp;</td>
</tr>
<tr>
	<td nowrap><b>Avg. by Group</b></td>
	<td>&nbsp;</td>
<% 
	for (int y=0;y<lAl_groupNameList.size();y++)
	{
		String ls_group = "";
		ls_group = (String)lAl_groupNameList.get(y);
		Float grouphours = new Float(0f);
		grouphours = (Float)lHs_groupTotal.get(ls_group);
		float grouppercent = Math.round(grouphours.floatValue()*10000f/lF_total.floatValue())/100f;
%>
	<td width=60 align='right'><%=num.getFixNum(String.valueOf(grouppercent),2)%>%</td>
<% 
	}
%>
	<td width=60 align='right'>100.00%</td>
	<td>&nbsp;</td>
	<td>&nbsp;</td>
	<td>&nbsp;</td>
	<td>&nbsp;</td>
	<td>&nbsp;</td>
</tr>
<tr>
	<td nowrap><b>Cost by Group</b></td>
	<td>&nbsp;</td>
<%
	float lSumCost = 0f;
	for (int z=0;z<lAl_groupNameList.size();z++)
	{
		Float cost = new Float(0f);
		String ls_GroupName = (String)lAl_groupNameList.get(z);
		cost = (Float)lHs_costList.get(ls_GroupName);
		if(cost.floatValue()==0f)
		{
%>
	<td width=60 align='right'>*</td>
<%               
		}
		else
		{
%>
		<td width=60 align='right'><%=num.getFixNum(cost.toString(),-1)%></td>
<%
			lSumCost = lSumCost + cost.floatValue();	
		}		
	} 
%>
        <td width=60>&nbsp;</td>
        <td>&nbsp;</td>
<%      
		if(lSumCostBoolean)
        {
			Float result = new Float(lSumCost);
%>
		<td width=60 align='right'><%=num.getFixNum(result.toString(),-1)%></td>
<%      }
        else
        {  
%>
		<td width=60 align='right'>*</td>
<%       
		}      
%>
		<td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
</tr>
</table>
<%
}
%>

<br>
<hr>
<p>
<INPUT type=button value=Back onclick="location.href='<%=contextPath%>/tss/projectreport/ProjectReport.jsp'">
</p>
</body>
<%@ include file="../tssfooter.jsp" %>
</html>
